package com.ruoyi.business.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.CzEquipment;
import com.ruoyi.business.service.ICzEquipmentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备Controller
 * 
 * @author ruoyi
 * @date 2022-01-09
 */
@Api(tags = "设备")
@RestController
@RequestMapping("/business/equipment")
public class CzEquipmentController extends BaseController
{
    @Autowired
    private ICzEquipmentService czEquipmentService;

    /**
     * 查询设备列表
     */
    @ApiOperation(value = "查询设备列表")
    @PreAuthorize("@ss.hasPermi('business:equipment:list')")
    @GetMapping("/list")
    public TableDataInfo list(CzEquipment czEquipment)
    {
        startPage();
        List<CzEquipment> list = czEquipmentService.selectCzEquipmentList(czEquipment);
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    @ApiOperation(value = "导出设备列表")
    @PreAuthorize("@ss.hasPermi('business:equipment:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CzEquipment czEquipment)
    {
        List<CzEquipment> list = czEquipmentService.selectCzEquipmentList(czEquipment);
        ExcelUtil<CzEquipment> util = new ExcelUtil<CzEquipment>(CzEquipment.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取设备详细信息
     */
    @ApiOperation(value = "获取设备详细信息")
    @PreAuthorize("@ss.hasPermi('business:equipment:query')")
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") String equipmentId)
    {
        return AjaxResult.success(czEquipmentService.selectCzEquipmentByEquipmentId(equipmentId));
    }

    /**
     * 新增设备
     */
    @ApiOperation(value = "新增设备")
    @PreAuthorize("@ss.hasPermi('business:equipment:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CzEquipment czEquipment)
    {
        return toAjax(czEquipmentService.insertCzEquipment(czEquipment));
    }

    /**
     * 修改设备
     */
    @ApiOperation(value = "修改设备")
    @PreAuthorize("@ss.hasPermi('business:equipment:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CzEquipment czEquipment)
    {
        return toAjax(czEquipmentService.updateCzEquipment(czEquipment));
    }

    /**
     * 删除设备
     */
    @ApiOperation(value = "删除设备")
    @PreAuthorize("@ss.hasPermi('business:equipment:remove')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
    public AjaxResult remove(@PathVariable String[] equipmentIds)
    {
        return toAjax(czEquipmentService.deleteCzEquipmentByEquipmentIds(equipmentIds));
    }
}
